﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace HQWeb.Resources
{
    public partial class TypeTree : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //VerdictIsLogin();
            if (!IsPostBack)
            {
                InitTree();
            }
        }

        #region 元素类型树
        private void InitTree()
        {
            TreeNode node = new TreeNode();
            node.Text = "元素分类";
            node.Value = "0";
            node.Target = "mainFrame";
            node.Expanded = true;
            node.SelectAction = TreeNodeSelectAction.Expand;
            node.NavigateUrl = "MaterialList.aspx?pid=0";
            IList TreeList = new ArrayList();
            BLL.SysManage.T_PUB_MATERIALTYPE MaterialBll = new BLL.SysManage.T_PUB_MATERIALTYPE();
            TreeList = MaterialBll.GetModelList("ISUSED='1'");
            AddReplies(node, TreeList);
            LeftTree.Nodes.Add(node);
        }
        #endregion

        #region 加载元素类型下元素节点
        private void AddReplies(TreeNode node, IList TreeList)
        {
            try
            {
                string strPid = node.Value;
                foreach (Model.SysManage.T_PUB_MATERIALTYPE Material in TreeList)
                {
                    if (Material.PARENT_ID.ToString() == strPid)
                    {
                        TreeNode replyNode = new TreeNode();
                        replyNode.Text = Material.TYPE_NAME.Trim();
                        replyNode.Value = Material.TYPE_ID.ToString();
                        replyNode.NavigateUrl = "MaterialList.aspx?pid=" + replyNode.Value;
                        replyNode.Target = "mainFrame";
                        replyNode.Expanded = false;
                        replyNode.SelectAction = TreeNodeSelectAction.Expand;
                        node.ChildNodes.Add(replyNode);
                        AddReplies(replyNode, TreeList);
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }
}